package com.seeqool.v1.chartframes;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import com.seeqool.v1.datamodel.SQLTable;

public class Bar100ChartFrame extends BaseChartFrame {

	private static final long serialVersionUID = 1L;

	public Bar100ChartFrame(SQLTable queryResult, int majorAxis, Integer[] minorAxes) {
		super("100% Bar Chart");
		DefaultCategoryDataset cdata = new DefaultCategoryDataset();
		for (int r=0; r<queryResult.getRowCount(); r++) {
			double s=0;
			for (Integer a : minorAxes)
				s+=Math.abs((Float) queryResult.getValueAt(r, a));
			if (s>0) {
				for (Integer a : minorAxes)
					cdata.addValue(Math.abs((Float) queryResult.getValueAt(r, a))/s*100, a.toString(), queryResult.getValueAt(r, majorAxis).toString());
			}
		}
		addContent(new ChartPanel(ChartFactory.createStackedBarChart("Test", "x", "y", cdata, PlotOrientation.HORIZONTAL, true, true, false)));
	}
}
